﻿Imports System.Data.Linq
Imports System.Linq

Public Class VoyageRepository

    'Private dc As New TanNamChinhDataContext

    'Public Sub New()
    '    dc = GeneralClassDAL.dc
    'End Sub

    'Public Function CreateNew() As tblVoyage
    '    Return New tblVoyage()
    'End Function

    'Public Function SelectAllRecord() As IQueryable(Of tblVoyage)
    '    Return dc.tblVoyages
    'End Function

    'Public Function SelectRecordById(ByVal id As Integer) As tblVoyage
    '    Return dc.tblVoyages.SingleOrDefault(Function(p As tblVoyage) p.ID_Voyage = id)
    'End Function

    'Public Function Insert(ByVal obj As tblVoyage) As tblVoyage
    '    dc.tblVoyages.InsertOnSubmit(obj)
    '    dc.SubmitChanges()
    '    Return obj
    'End Function

    'Public Sub Update(ByVal obj As tblVoyage)
    '    dc.Refresh(RefreshMode.KeepChanges, obj)
    '    dc.SubmitChanges(ConflictMode.ContinueOnConflict)
    'End Sub

    ' ''' <summary>
    ' ''' Chọn những chuyến tàu sắp chạy thỏa điều kiện:
    ' ''' + Có chuyến tàu là VoyageNo thuộc hãng tàu cụ thể
    ' ''' + Ngày dự kiến chạy ETD phải > ngày hiện tại
    ' ''' </summary>
    ' ''' <param name="id_vessel"></param>
    ' ''' <returns></returns>
    ' ''' <remarks></remarks>
    'Public Function SelectCommingVoyage(ByVal id_vessel As Integer) As IQueryable(Of tblVoyage)
    '    Dim obj = From p In dc.tblVoyages
    '              Where p.ID_Vessel = id_vessel _
    '              And p.ETD.Value > Date.Now.Date
    '              Select p
    '    Return obj
    'End Function

    ' ''' <summary>
    ' ''' Lấy Voyage theo các thông tin khác
    ' ''' </summary>
    ' ''' <param name="objVoyage"></param>
    ' ''' <returns></returns>
    ' ''' <remarks></remarks>
    'Public Function SelectVoyageByInformation(ByVal objVoyage As tblVoyage) As tblVoyage
    '    Dim query = From p In dc.tblVoyages
    '            Where p.VoyageNo = objVoyage.VoyageNo _
    '              And p.ID_Vessel = objVoyage.ID_Vessel.Value _
    '              And p.ID_POD.Value = objVoyage.ID_POD.Value _
    '              And p.ID_POL.Value = objVoyage.ID_POL.Value _
    '              And p.ETA.Value = objVoyage.ETA.Value _
    '              And p.ETD.Value = objVoyage.ETD.Value
    '              Select p

    '    Dim obj As tblVoyage
    '    For Each o As tblVoyage In query
    '        obj = o
    '    Next

    '    If obj Is Nothing Then
    '        obj = Insert(objVoyage)
    '    End If
    '    Return obj
    'End Function

    ' ''' <summary>
    ' ''' Lấy Voyage theo VoyageNo
    ' ''' </summary>
    ' ''' <param name="ID_Vessel"></param>
    ' ''' <param name="voyageNo"></param>
    ' ''' <returns></returns>
    ' ''' <remarks></remarks>
    'Public Function SelectVoyageByVoyageNo(ByVal ID_Vessel As Integer, ByVal voyageNo As String) As tblVoyage
    '    Return dc.tblVoyages.SingleOrDefault(Function(p As tblVoyage) _
    '    p.VoyageNo = voyageNo _
    '      And p.ID_Vessel = ID_Vessel _
    '      And p.ETD.Value > Now.Date())
    'End Function
End Class
